package com.best.core.exception;

/**
 * @ClassName: CommonException
 * @Package: com.best.core.exception
 * @Description: 自定义异常类
 * @Datetime: 2020/6/5 17:54
 * @Author: nike
 */
public class CommonException extends RuntimeException {

    // 异常码
    private CommonExceptionCode commonExceptionCode;
    // 异常信息字符串数组
    private String[] exceptionMsgs;

    public CommonException(CommonExceptionCode commonExceptionCode) {
        this.commonExceptionCode = commonExceptionCode;
    }

    public CommonException(CommonExceptionCode commonExceptionCode, String... exceptionMsgs) {
        this.commonExceptionCode = commonExceptionCode;
        this.exceptionMsgs = exceptionMsgs;
    }

    public CommonExceptionCode getCommonExceptionCode() {
        return commonExceptionCode;
    }

    @Override
    public String getMessage() {
        return this.exceptionMsgs != null
                ? String.format(commonExceptionCode.getMsg(), exceptionMsgs)
                : commonExceptionCode.getMsg();
    }
}
